package com.xbongbong.saas.script.tempenum;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.paas.enums.DateTimeEnum;
import com.xbongbong.paas.enums.DefaultTypeEnum;
import com.xbongbong.paas.enums.DefaultValueEnum;
import com.xbongbong.paas.enums.FieldTypeEnum;
import com.xbongbong.paas.help.FormDataFormExplainHelper;
import com.xbongbong.paas.field.DefaultAttrPoJo;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.ItemPoJo;
import com.xbongbong.paas.field.LinkDetailPojo;
import com.xbongbong.paas.field.SubFormPoJo;
import com.xbongbong.pro.enums.AmountFlagEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.saas.constant.StringConstant;
import com.xbongbong.saas.enums.ForbiddenSettingEnum;
import com.xbongbong.saas.enums.PhoneExtEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.SupplierEnum;
import com.xbongbong.saas.script.help.InitExplainsHelper;
import com.xbongbong.sys.enums.RoleEnum;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import lombok.Getter;

/**
 * 供应商
 *
 * @author Jian.Wang
 * @version v1.0
 * @date 2019/1/16
 * @since v1.0
 */
@Getter
public enum TempSupplierEnum {
    // 供应商中间枚举
    BASE_INFO(SupplierEnum.BASE_INFO),
    SUPPLIER_NAME(SupplierEnum.SUPPLIER_NAME),
    SHORT_NAME(SupplierEnum.SHORT_NAME),
    PHONE(SupplierEnum.PHONE),
    OWNER_ID(SupplierEnum.OWNER_ID),
    COUSERID(SupplierEnum.COUSERID),
    THUMBNAIL(SupplierEnum.THUMBNAIL),
    MEMO(SupplierEnum.MEMO),

    ASSOCIATED_INFO(SupplierEnum.ASSOCIATED_INFO),
    ADD_SUPPLIER_CONTACT(SupplierEnum.ADD_SUPPLIER_CONTACT),
    PRODUCT_LIST(SupplierEnum.PRODUCT_LIST),

    EXTEND_INFO(SupplierEnum.EXTEND_INFO),
    QUALITY_STANDARD(SupplierEnum.QUALITY_STANDARD),
    SUPPLY_COST(SupplierEnum.SUPPLY_COST),
    DELIVERY_CAPACITY(SupplierEnum.DELIVERY_CAPACITY),
    SERVER_CAPACITY(SupplierEnum.SERVER_CAPACITY),
    CREDIT_LEVEL(SupplierEnum.CREDIT_LEVEL),
    REGISTERED_CAPITAL(SupplierEnum.REGISTERED_CAPITAL),
    COUNTRY(SupplierEnum.COUNTRY),
    ADDRESS(SupplierEnum.ADDRESS),
    WEBSITE(SupplierEnum.WEBSITE),
    ANNUAL_OUTPUT(SupplierEnum.ANNUAL_OUTPUT),

    SYSTEM_INFO(SupplierEnum.SYSTEM_INFO),
    CREATOR_ID(SupplierEnum.CREATOR_ID),
    ADD_TIME(SupplierEnum.ADD_TIME),
    UPDATE_TIME(SupplierEnum.UPDATE_TIME),
    LAST_CONNECT_TIME(SupplierEnum.LAST_CONNECT_TIME),
    CONTACT(SupplierEnum.CONTACT),
    ;
    private SupplierEnum anEnum;

    TempSupplierEnum(SupplierEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempSupplierEnum> getAllEnum() {
        List<TempSupplierEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }
    /**
     * 初始化供应商名称
     *
     * @param fieldAttrEntity 字段解释实体--saas专用
     */
    public static void initSupplierName(FieldAttrEntity fieldAttrEntity){
        LinkDetailPojo linkDetailPojo = new LinkDetailPojo();
        linkDetailPojo.setBusinessType(XbbRefTypeEnum.SUPPLIER.getCode());
        linkDetailPojo.setSubBuisenssType(XbbRefTypeEnum.SUPPLIER.getCode());
        linkDetailPojo.setSaasMark(SaasMarkEnum.SAAS.getCode());
        linkDetailPojo.setAttr(SUPPLIER_NAME.getAnEnum().getAttr());
        fieldAttrEntity.setLinkDetail(linkDetailPojo);
        fieldAttrEntity.setNoRepeat(1);
        fieldAttrEntity.setIsForbidden(0);
    }
    /**
     * 初始化国家下拉
     *
     * @author Jian.Wang
     * @date 2019/1/16 15:45
     */
    public static void initCountry(FieldAttrEntity fieldAttrEntity) {
        String str = "中国,美国,澳大利亚,巴西,英国,加拿大,埃及,法国,德国,希腊,印度,爱尔兰,日本,新加坡";
        fieldAttrEntity.setItems(InitExplainsHelper.setCombItem(str));
    }

    /**
     * 初始化联系电话
     *
     * @param fieldAttrEntity 字段解释实体
     */
    public static void initPhone(FieldAttrEntity fieldAttrEntity) {
        SubFormPoJo subFormPoJo = new SubFormPoJo();
        List<FieldAttrEntity> items = new ArrayList<>();
        FieldAttrEntity item = InitExplainsHelper.setField("text_1", "类型", "type", FieldTypeEnum.COMBO.getType(), 4, 1, 0, 1);
        List<ItemPoJo> itemPoJoList = InitExplainsHelper.setCombItemByEnum(PhoneExtEnum.class, FieldTypeEnum.COMBO.getType());
        itemPoJoList.get(0).setChecked(true);
        item.setItems(itemPoJoList);
        item.setRequired(1);
        item.setParentAttr(PHONE.anEnum.getAttr());
        item.setDictionaryFlag(1);
        items.add(item);
        FieldAttrEntity item2 = InitExplainsHelper.setField("text_2", "电话", "phone", FieldTypeEnum.TEXT.getType(), 4, 1, 0, 1);
        item2.setRequired(1);
        item2.setParentAttr(PHONE.anEnum.getAttr());
        items.add(item2);
        subFormPoJo.setItems(items);
        fieldAttrEntity.setSubForm(subFormPoJo);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType("custom");
        defaultAttrPoJo.setDefaultValue("");
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setRequired(1);
        fieldAttrEntity.setIsForbidden(1);
    }

    public static void initRegisteredCapital(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
    }

    public static void initLastConnectTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setRecentTime(true);
        fieldAttrEntity.setDateType(DateTimeEnum.DATETIME.getType());
    }

    /**
     * 负责人
     * @param fieldAttrEntity
     */
    public static void initOwnerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setMultiple(1);
        fieldAttrEntity.setRequired(1);
        //可新增权限：默认【超级管理员、销售主管、创建人、负责人、负责人主管】可新增协同人，支持自定义；
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setUnableEditMemo(null);
        DefaultAttrPoJo defaultAttrPoJo = new DefaultAttrPoJo();
        defaultAttrPoJo.setDefaultType(DefaultTypeEnum.DYNAMIC.getAlias());
        defaultAttrPoJo.setDefaultValue(DefaultValueEnum.LOGIN_USER.getValue());
        fieldAttrEntity.setDefaultAttr(defaultAttrPoJo);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.PURCHASE_MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.PURCHASE_MANAGER));
    }

    public static void initCoUserId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setRequired(0);
        //可新增权限：默认【超级管理员、销售主管、创建人、负责人、负责人主管】可新增协同人，支持自定义；
        fieldAttrEntity.setShowEditable(0);
        fieldAttrEntity.setAdd(1);
        fieldAttrEntity.setAddAdvanceEnable(1);
        fieldAttrEntity.setShowAdd(1);
        fieldAttrEntity.setRemove(1);
        fieldAttrEntity.setRemoveAdvanceEnable(1);
        fieldAttrEntity.setShowRemove(1);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setEditable(1);
        fieldAttrEntity.setUnableEditMemo(null);
        fieldAttrEntity.setAddRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.PURCHASE_MANAGER));
        fieldAttrEntity.setRemoveRule(FormDataFormExplainHelper.getDefaultRule(RoleEnum.PURCHASE_MANAGER));
    }

    public static void initCreatorId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initAddTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }
    public static void initUpdateTime(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setEditable(0);
        fieldAttrEntity.setUnableEditMemo(I18nMessageUtil.getMessage(StringConstant.AUTO_GEN_FIELD));
    }

    public static void initProducts(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setForbiddenSettingList(Collections.singletonList(ForbiddenSettingEnum.DISABLE_RULE.getAlias()));
        fieldAttrEntity.setIsForbidden(0);
    }


    public static void initAddSupplierContact(FieldAttrEntity fieldAttrEntity) {
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setLinkBusinessType(XbbRefTypeEnum.SUPPLIER_CONTACT.getCode());
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
    }



}
